"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const koa2_cors_1 = __importDefault(require("koa2-cors"));
const koa_compress_1 = __importDefault(require("koa-compress"));
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
const koa_range_1 = __importDefault(require("koa-range"));
const resourcesProxy_1 = __importDefault(require("./proxy/resourcesProxy"));
const errHandler_1 = __importDefault(require("./lib/errHandler"));
const AppFileRoutes_1 = __importDefault(require("../routes/AppFileRoutes"));
const ProxyRoutes_1 = __importDefault(require("../routes/ProxyRoutes"));
const DBRoutes_1 = __importDefault(require("../routes/DBRoutes"));
const AuthorizeRoutes_1 = __importDefault(require("../routes/AuthorizeRoutes"));
const configTool_1 = __importDefault(require("../com/configTool"));
const logHandler_1 = __importDefault(require("./lib/logHandler"));
const IPAuthorityHandler_1 = __importDefault(require("./lib/IPAuthorityHandler"));
const MapServicesRoutes_1 = __importDefault(require("../routes/MapServicesRoutes"));
const TileRoutes_1 = __importDefault(require("../routes/TileRoutes"));
const plugsRoutes_1 = __importDefault(require("../../plug/routes/plugsRoutes"));
const plugsMiddlewares_1 = __importDefault(require("../../plug/middleware/plugsMiddlewares"));
const TokenAuthorityHandler_1 = __importDefault(require("./lib/TokenAuthorityHandler"));
const ManaRoutes_1 = __importDefault(require("../routes/ManaRoutes"));
const WindowsInfo_1 = __importDefault(require("../routes/WindowsInfo"));
const DocRoutes_1 = __importDefault(require("../routes/DocRoutes"));
const responseSISFormat_1 = __importDefault(require("./lib/responseSISFormat"));
const { koaSwagger } = require('koa2-swagger-ui');
function clientMiddleWare(app) {
    configTool_1.default.baseConfig.clientCORS && app.use((0, koa2_cors_1.default)());
    const baseConfig = configTool_1.default.baseConfig;
    app.use(koaSwagger({
        routePrefix: '/doc',
        hideTopbar: false,
        favicon: '/favicon.ico',
        swaggerOptions: {
            url: `http://${baseConfig.localIPAddress}:${baseConfig.proxyAfterProxy_Port}/Doc/api`
        }
    }));
    app.use((0, koa_bodyparser_1.default)({
        formLimit: '20mb',
        jsonLimit: '20mb'
    }));
    app.use((0, koa_compress_1.default)({ br: false }));
    app.use((0, responseSISFormat_1.default)());
    app.use((0, errHandler_1.default)());
    app.use((0, logHandler_1.default)());
    app.use((0, IPAuthorityHandler_1.default)(['*'], configTool_1.default.baseConfig.blackList));
    app.use(koa_range_1.default);
    app.use(ProxyRoutes_1.default.routes());
    app.use(MapServicesRoutes_1.default.routes());
    app.use(AppFileRoutes_1.default.routes());
    app.use(DBRoutes_1.default.routes());
    app.use(TileRoutes_1.default.routes());
    app.use(AuthorizeRoutes_1.default.routes());
    app.use((0, TokenAuthorityHandler_1.default)());
    (0, resourcesProxy_1.default)(app, configTool_1.default.wwwPath);
    app.use(ManaRoutes_1.default.routes());
    app.use(WindowsInfo_1.default.routes());
    app.use(DocRoutes_1.default.routes());
    for (let i = 0; i < plugsMiddlewares_1.default.length; i++) {
        app.use(plugsMiddlewares_1.default[i]());
    }
    for (let i = 0; i < plugsRoutes_1.default.length; i++) {
        app.use(plugsRoutes_1.default[i].routes());
    }
}
exports.default = clientMiddleWare;
